/*
 * @Date: 2022-02-23 15:52:50
 * @LastEditors: wuyuxin
 * @LastEditTime: 2022-02-23 16:56:32
 * @FilePath: \webpack-learning\26_自定义Loader\loaders\hy-loader01.js
 * @description: 文件描述
 */
const { getOptions } = require('loader-utils')
const { validate } = require('schema-utils')

const schema = require('../schema/loader01-schema.json')
// 异步loader
module.exports = function(content) {
  console.log(content, 'testContent==========loader01')

  // 获取传入的参数
  const options = getOptions(this);
  console.log("传入的参数是：", options)

  validate(schema, options, {
    name: "hy-loader01"
  })

  const callback = this.async()
  
  setTimeout(() => {
    callback(null, content)
  }, 2000)
}

// 同步loader
// module.exports = function(content) {
//   console.log(content, 'testContent==========loader01')
//   // return content;
//   this.callback(null, content)
// }

module.exports.pitch = function () {
  console.log("loader pitch 01");
}